<?php


namespace EchoPHP\Foundation\Exception;


use Whoops\Handler\PrettyPageHandler;

class WhoopsHandler {

    /**
     * 调试模式下准备PrettyPageHandler
     * @return PrettyPageHandler
     * @throws \Exception
     */
    public function forDebug() {
        $handler = new PrettyPageHandler();

        $handler->handleUnconditionally(true);
        $this->registerBlacklist($handler);

        return $handler;
    }

    /**
     * 注册隐藏项
     * @param PrettyPageHandler $handler
     * @throws \Exception
     * @return $this
     */
    protected function registerBlacklist($handler) {
        foreach (config('app.debug_blacklist', []) as $key => $secrets) {
            foreach ($secrets as $secret) {
                $handler->blacklist($key, $secret);
            }
        }
        return $this;
    }


}